package com.yqyd.web.controller.nbot.app;


import com.yqyd.common.constant.NbotConstans;
import com.yqyd.common.core.domain.R;
import com.yqyd.common.utils.SecurityUtils;
import com.yqyd.nbot.domain.NbotActivity;
import com.yqyd.nbot.domain.NbotBackground;
import com.yqyd.nbot.domain.NbotMenu;
import com.yqyd.nbot.service.INbotActivityService;
import com.yqyd.nbot.service.INbotBackgroundService;
import com.yqyd.nbot.service.INbotMenuService;
import com.yqyd.nbot.service.INbotUserNumberService;
import com.yqyd.system.service.ISysUserService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/nbot/home")
@CrossOrigin
public class HomeApi {

    @Resource
    private INbotMenuService menuService;

    @Resource
    private INbotActivityService activityService;

    @Resource
    private ISysUserService userService;

    @Resource
    private INbotUserNumberService userNumberService;

    @Resource
    private INbotBackgroundService backgroundService;

    private static final Integer HIDE = 0;

    @GetMapping("/Data")
    public R<Map<String, Object>> Data() {
        Map<String, Object> map = new HashMap<>();
        Long userId = SecurityUtils.getUserId();
        // 获取个人的信息
        map.put("Info", userService.selectEasyUserByUserId(userId));
        // 获取用户的数据
        map.put("Data", userNumberService.selectNbotUserNumberByUserId(userId));
        // 获取快捷功能
        map.put("Menu", menuService.selectNbotMenuList(new NbotMenu().setHide(HIDE)));
        // 获取活动 (可报名的活动)
        map.put("Activity", activityService.selectNbotActivityList(new NbotActivity().setAuditStatus(NbotConstans.ACT_AUDIT_PASS).setStatus(NbotConstans.ACT_STATUS_PENDING)));
        // 背景图
        map.put("Background", backgroundService.selectNbotBackgroundList(new NbotBackground()));
        return R.ok(map);
    }

}
